package com.yunhe.authority.service.authority;

import com.yunhe.authority.domain.authority.BackUser;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.PageParam;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhengbo
 * @date 2021/10/21 15:34
 */
public interface BackUserService {

    /**
     * 新增
     * @param backUser
     * @param roleIds
     * @return
     * @throws ArgumentErrorException
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    BackUser save(BackUser backUser, String roleIds) throws ArgumentErrorException;

    /**
     * 更新
     * @param backUser
     * @return
     * @throws ArgumentErrorException
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    BackUser update(BackUser backUser) throws ArgumentErrorException;

    /**
     * 修改密码
     * @param id 用户ID
     * @param password 用户密码
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    BackUser updatePassword(@Param("id") Long id, @Param("password") String password);

    /**
     * 根据用户名密码查询后台账号
     * @param name 用户名
     * @param password 用户密码
     */
    BackUser findByNameAndPassword(@Param("name") String name, @Param("password") String password);

    /**
     * 根据手机号密码查询后台账号
     * @param phone 手机号
     * @param password 用户密码
     */
    BackUser findByPhoneAndPassword(@Param("phone") String phone, @Param("password") String password) throws ArgumentErrorException;

    /**
     * 根据用户名查询后台账号
     * @param name 用户名
     */
    BackUser findByName(@Param("name") String name);

    /**
     * 根据手机号查询后台账号
     * @param phone 手机号
     */
    BackUser findByPhone(@Param("phone") String phone);

    /**
     * 根据id查询
     * @param userId
     * @return BackUser
     */
    BackUser findByUserId(Long userId);

    /**
     *
     * @param id
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void deleteById(Long id);

    Page<BackUser> findUsersByIdAndCondition(Long id, String keywords, PageParam pageParam);
}
